using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using UWBGL_WinForms_Lib1;
using UWBGL_XNA_Lib10;

namespace XNA_WCSupport
{
  public partial class XNA_WCSupport : Form
  {
		// handler declaration
    private DrawOnlyHandler _view_zoomed;
		private DrawAndMouseHandler _view_big;

    private UWB_BoundingBox worldBound_Big, worldBound_Small;
		private int _hBig, _wBig, _hSmall, _wSmall;
    private Timer mTimer;

    public XNA_WCSupport()
    {
			// handler initialization
      _view_zoomed = new DrawOnlyHandler();
			_view_big = new DrawAndMouseHandler();

			_hBig = _wBig = 400;
			_hSmall = 170;
			_wSmall = 200;
			
      mTimer = new Timer();
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
			_view_zoomed.SetWCWindow(Program.getModel().GetWorldBounds());
			_view_big.SetWCWindow(new UWB_BoundingBox(new Vector3(0, 0, 0), new Vector3(36, 36, 0)));
			_view_big.SetLinkedHandler(_view_zoomed);

			// link handler to GUI area
			PlaceHolder_Graphics.Height = _hBig;
			PlaceHolder_Graphics.Width = _wBig;
			placeholder_small.Height = _hSmall;
			placeholder_small.Width = _wSmall;
      _view_zoomed.Initialize(placeholder_small); // small
			_view_big.Initialize(PlaceHolder_Graphics); // big

      worldBound_Big = new UWB_BoundingBox(new Vector3(0, 0, 0), new Vector3(36, 36, 0));
			worldBound_Small = new UWB_BoundingBox(new Vector3(0, 0, 0), new Vector3(10, 10, 0));
      _view_zoomed.setWCWindow(ref worldBound_Small);
			_view_big.setWCWindow(ref worldBound_Big);

      //UWBGL_XNA_Lib10.UWB_Utility.mEchoTextBox = echoTextBox;

      //set our timer's interval in milliseconds and set the mTimer_Tick function to be
      //called every time it reaches that interval
      mTimer.Interval = 25;
      mTimer.Tick += new EventHandler(mTimer_Tick);
      mTimer.Start();

			sliderControlWithEcho1.ChangeRangeValues(1, 100, 100); // setup slider

      UWBGL_XNA_Lib10.UWB_Utility.echoToStatusArea("Form Load Complete");

			
    }

    private void Button_Quit_Click(object sender, EventArgs e)
    {
      Close();
    }

		// event handler for timer
    private void mTimer_Tick(object sender, EventArgs e)
    {
      Program.getModel().updateSimulation();

			// periodic updates to graphics area
      _view_zoomed.DrawGraphics();
			_view_big.DrawGraphics();

			// updates for mouse location
			currentLocation.Text = Program.getModel().HoverLocation;
			label_hwX.Text = "X: " + Program.getModel().hardwareX.ToString();
			label_hwY.Text = "Y: " + Program.getModel().hardwareY.ToString();
			label_dvX.Text = "X: " + Program.getModel().deviceX.ToString();
			label_dvY.Text = "Y: " + Program.getModel().deviceY.ToString();
			label_wdX.Text = Program.getModel().worldX.ToString();
			label_wdY.Text = Program.getModel().worldY.ToString();

			// updates for window sizes
			label_windowBigX.Text = "Width: " + _view_big.Width.ToString();
			label_windowBigY.Text = "Height: " + _view_big.Height.ToString();
			label_windowSmallX.Text = "Width: " + _view_zoomed.Width.ToString();
			label_windowSmallY.Text = "Height: " + _view_zoomed.Height.ToString();

			// updates for zoomed-window's origin and size in WORLD coordinates
			label_SmallOriginWCX.Text = Program.getModel().originWCSmallX.ToString();
			label_SmallOriginWCY.Text = Program.getModel().originWCSmallY.ToString();
			label_SmallSizeWCX.Text = Program.getModel().sizeWCSmallX.ToString();
			label_SmallSizeWCY.Text = Program.getModel().sizeWCSmallY.ToString();
    }

		// capture hardware mouse location for MAIN window
		protected override void OnMouseMove(MouseEventArgs e)
		{
			label_hwX.Text = "X: " + e.X.ToString();
			label_hwY.Text = "Y: " + e.Y.ToString();
			label_dvX.Text = "X: " + "--";
			label_dvY.Text = "Y: " + "--";
			label_wdX.Text = "X: " + "--";
			label_wdY.Text = "Y: " + "--";
			currentLocation.Text = "Main dialog";
		}

		private void xFormInfoControl1_Load(object sender, EventArgs e)
		{

		}

		private void sliderControlWithEcho1_Scroll(object sender, EventArgs e)
		{
			PlaceHolder_Graphics.Width = (int)(((float)_wBig) * (sliderControlWithEcho1.GetSliderValue() / 100f));
			_view_big.Initialize(PlaceHolder_Graphics);

			placeholder_small.Width = (int)(((float)_wSmall) * (sliderControlWithEcho1.GetSliderValue() / 100f));
			_view_zoomed.Initialize(placeholder_small);

			if (checkBox_squareView.Checked) // square views for all 
			{
				PlaceHolder_Graphics.Height = PlaceHolder_Graphics.Width;
				_view_big.Initialize(PlaceHolder_Graphics);

				placeholder_small.Height = placeholder_small.Width;
				_view_zoomed.Initialize(placeholder_small);
			}
		}

		private void checkBox_squareView_CheckedChanged(object sender, EventArgs e)
		{
			PlaceHolder_Graphics.Height = PlaceHolder_Graphics.Width;
			_view_big.Initialize(PlaceHolder_Graphics);

			placeholder_small.Height = placeholder_small.Width;
			_view_zoomed.Initialize(placeholder_small);

			if (!checkBox_squareView.Checked)
			{
				PlaceHolder_Graphics.Height = _hBig;
				_view_big.Initialize(PlaceHolder_Graphics);

				placeholder_small.Height = _hSmall;
				_view_zoomed.Initialize(placeholder_small);
			}
		}

  }
}
